<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>随访档案详情</title>
  <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
  <!-- <link rel="stylesheet" href="../../css/public.css" media="all"> -->
</head>
<style> .layui-form-label {
  width: 150px !important;
  text-align: center !important;
}

.layui-input-block {
  margin-left: 150px !important;
}
</style>
<body>
  <div class="layuimini-container">
    <div class="layuimini-main">

      <!-- <fieldset class="table-search-fieldset"> -->
      <div style="margin: 10px 10px 10px 10px">
        <div class="layui-form layui-form-pane" action="">
          <div class="layui-form-item">
            <div class="layui-form-item">
              <label class="layui-form-label">id号</label>
              <div class="layui-input-block">
                <input type="text" id="id" name="id" autocomplete="off" autocomplete="off"
                  class="layui-input" disabled>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">患者姓名</label>
                <div class="layui-input-block">
                  <input type="text" id="realName" name="realName" autocomplete="off" autocomplete="off"
                    class="layui-input" lay-verify="realName|required">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">患者手机号</label>
                <div class="layui-input-block">
                  <input type="text" id="phoneNum" name="phoneNum" autocomplete="off" autocomplete="off"
                    class="layui-input" lay-verify="phoneNum|required">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">家属手机号</label>
                <div class="layui-input-block">
                  <input type="text" id="dependentNum" name="dependentNum" autocomplete="off" autocomplete="off"
                    class="layui-input" lay-verify="phoneNum|required">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">身份证号</label>
                <div class="layui-input-block">
                  <input type="text" id="idNumber" name="idNumber" autocomplete="off" autocomplete="off"
                    class="layui-input" lay-verify="idNumber|required">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">植入原因</label>
              <div class="layui-input-block">
                <input type = "radio" name = "reason" value = "病窦" title = "病窦" lay-filter="reason" checked="true">
                <input type = "radio" name = "reason" id = "reason_1" value = "房室传导阻滞一度" title = "房室传导阻滞x级" lay-filter="reason">
                <input type = "radio" name = "reason" value = "房颤伴长RR间期" title = "房颤伴长RR间期" lay-filter="reason">
                <input type = "radio" name = "reason" value = "晕厥" title = "晕厥" lay-filter="reason">
                <input type = "radio" name = "reason" id = "reason_2" value = "心衰1级" title = "心衰x级" lay-filter="reason">
                <input type = "radio" name = "reason" value = "心肌病" title = "心肌病" lay-filter="reason">
                <input type = "radio" name = "reason" value = "冠心病" title = "冠心病" lay-filter="reason">
                <input type = "radio" name = "reason" value = "心脏骤停" title = "心脏骤停" lay-filter="reason">
                <input type = "radio" name = "reason" id = "reason_3" value = "其他" title = "其他" lay-filter="reason">
                <div id="reason_more_1" class="layui-hide">
                  <select lay-filter="reason_more_1">
                    <option value="一度" >一度</option>
                    <option value="二度一型AVB">二度一型AVB</option>
                    <option value="二度二型AVB">二度二型AVB</option>
                    <option value="三度">三度</option>
                  </select>
                </div>
                <div  id="reason_more_2" class="layui-hide">
                  <select lay-filter="reason_more_1">
                    <option value="1级" >1级</option>
                    <option value="2级" >2级</option>
                    <option value="3级" >3级</option>
                    <option value="4级" >4级</option>
                  </select>
                </div>
                <input type="text" id="reason_more_3" autocomplete="off" autocomplete="off"
                  class="layui-input layui-hide" placeholder="请输入详细原因" lay-verify="reason|elseinfo">
              </div>
            </div>
            <div class="layui-form-item" >
              <label class="layui-form-label">详细介绍</label>
              <div class="layui-input-block">
                <textarea type="text" id="introduce" name="introduce" autocomplete="off" autocomplete="off"
                  class="layui-input"  style="height:80px;" lay-verify="intro_detail|required"></textarea>
              </div>
            </div>
            <fieldset class="layui-elem-field layui-field-title">
              <legend><a class="layui-form-mid layui-word-aux" style="font-size: 15px;" name="color-design">起搏器选择</a></legend>
            </fieldset>
            <div class="layui-form-item">
              <label class="layui-form-label">起搏器Id</label>
              <div class="layui-input-block">
                <select name = "pacemakerId" id = "pacemakerId" lay-search lay-verify="required">
                </select>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">是否起搏器依赖</label>
              <div class="layui-input-block">
                <select name = "pacemakerDepend">
                  <option value="1" >是</option>
                  <option value="2" >否</option>
                </select>
              </div>
            </div>
            <fieldset class="layui-elem-field layui-field-title">
              <legend><a class="layui-form-mid layui-word-aux" style="font-size: 15px;" name="color-design">电极信息</a></legend>
            </fieldset>
            <div class="layui-form-item">
              <label class="layui-form-label">植入位置</label>
              <div class="layui-input-block">
                <input type="checkbox" id="wireP1" name="wirePosition" value = "1" title="右心房" lay-skin="primary"  lay-filter="wirePosition" lay-verify="fuxuan"> 
                <input type="checkbox" id="wireP2" name="wirePosition" value = "2" title="右心室" lay-skin="primary"  lay-filter="wirePosition" lay-verify="fuxuan"> 
                <input type="checkbox" id="wireP3" name="wirePosition" value = "3" title="左心室" lay-skin="primary"  lay-filter="wirePosition" lay-verify="fuxuan"> 
              </div>
            </div>
            <fieldset class="layui-elem-field layui-hide" id = "wirePosition_1">
              <legend style="font-size: 15px;color: gray;">右心房</legend>
              <div class="layui-field-box">
                <div class="layui-form-item">
                  <div class="layui-inline">
                      <label class="layui-form-label">导线型号</label>
                      <div class="layui-input-inline">
                        <select name = "wireId_1" id = "wireId_1" lay-search lay-verify="checkrf">
                        </select>
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">阈值(V)/脉宽(ms)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="tdpw_1" id = "tdpw_1" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkrf">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">P/R波(mv)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="prwave_1" id = "prwave_1" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkrf">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">起搏阻抗(Ω)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="pacingImpedance_1" id = "pacingImpedance_1" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkrf">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">除颤能量(J)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="defibrillationEnergy_1" id = "defibrillationEnergy_1" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkrf">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">除颤阻抗(Ω)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="defibrillationImpedance_1" id = "defibrillationImpedance_1" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkrf">
                      </div>
                  </div>
                </div>
              </div>
            </fieldset>
            <fieldset class="layui-elem-field  layui-hide" id = "wirePosition_2">
              <legend style="font-size: 15px;color: gray;">右心室</legend>
              <div class="layui-field-box">
                <div class="layui-form-item">
                  <div class="layui-inline">
                      <label class="layui-form-label">导线型号</label>
                      <div class="layui-input-inline">
                        <select name = "wireId_2" id = "wireId_2" lay-search lay-verify="checkrs">
                        </select>
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">阈值(V)/脉宽(ms)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="tdpw_2" id = "tdpw_2" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkrs">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">P/R波(mv)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="prwave_2" id = "prwave_2" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkrs">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">起搏阻抗(Ω)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="pacingImpedance_2" id = "pacingImpedance_2" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkrs">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">除颤能量(J)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="defibrillationEnergy_2" id = "defibrillationEnergy_2" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkrs">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">除颤阻抗(Ω)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="defibrillationImpedance_2" id = "defibrillationImpedance_2" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkrs">
                      </div>
                  </div>
                </div>
              </div>
            </fieldset>
            <fieldset class="layui-elem-field  layui-hide" id = "wirePosition_3">
              <legend style="font-size: 15px;color: gray;">左心室</legend>
              <div class="layui-field-box">
                <div class="layui-form-item">
                  <div class="layui-inline">
                      <label class="layui-form-label">导线型号</label>
                      <div class="layui-input-inline">
                        <select name = "wireId_3" id = "wireId_3" lay-search lay-verify="checkls">
                        </select>
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">阈值(V)/脉宽(ms)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="tdpw_3" id = "tdpw_3" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkls">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">P/R波(mv)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="prwave_3" id = "prwave_3" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkls">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">起搏阻抗(Ω)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="pacingImpedance_3" id = "pacingImpedance_3" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkls">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">除颤能量(J)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="defibrillationEnergy_3" id = "defibrillationEnergy_3" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkls">
                      </div>
                  </div>
                  <div class="layui-inline">
                      <label class="layui-form-label">除颤阻抗(Ω)</label>
                      <div class="layui-input-inline">
                          <input type="text" name="defibrillationImpedance_3" id = "defibrillationImpedance_3" autocomplete="off" class="layui-input" lay-verify="wireRe_f|checkls">
                      </div>
                  </div>
                </div>
              </div>
            </fieldset>
            <fieldset class="layui-elem-field layui-field-title">
              <legend><a class="layui-form-mid layui-word-aux" style="font-size: 15px;" name="color-design">手术信息</a></legend>
            </fieldset>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">植入时间</label>
                <div class="layui-input-block">
                  <input type="text" id="createTime" name="createTime" autocomplete="off" autocomplete="off"
                    class="layui-input date-time" placeholder="点击以选择" lay-verify="datetime1|required">
                </div>    
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">手术者</label>
                <div class="layui-input-block">
                  <select name = "surgeon" id = "surgeon" lay-search lay-verify="required">
                  </select>
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">植入医院</label>
              <div class="layui-input-block">
                <input type="text" id="hospital" name="hospital" autocomplete="off" autocomplete="off" placeholder="中南医院"
                  class="layui-input" lay-verify="hospital">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">手术过程</label>
              <div class="layui-input-block">
                <textarea type="text" id="surgicalDetail" name="surgicalDetail" autocomplete="off" autocomplete="off"
                  class="layui-input" style="height:80px;" lay-verify="intro_detail|required"></textarea>
              </div>
            </div>
            <fieldset class="layui-elem-field layui-field-title">
              <legend><a class="layui-form-mid layui-word-aux" style="font-size: 15px;" name="color-design">随访初始化</a></legend>
            </fieldset>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">下次随访时间</label>
                <div class="layui-input-block">
                  <input type="text" id="nextTime" name="nextTime" autocomplete="off" autocomplete="off"
                    class="layui-input date-time" placeholder="点击以选择" lay-verify="datetime2|required">
                </div>      
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">已经随访次数</label>
                <div class="layui-input-block">
                  <input type="text" id="followCounts" name="followCounts" autocomplete="off" autocomplete="off"
                    class="layui-input" value="0" lay-verify="number">
                </div>
              </div>
            </div>
            <div style="position: absolute; right: 17px;">
              <button id="closebtn" type="button" class="layui-btn" style="margin-right: 0;" lay-submit lay-filter="saveBtn">保存提交</button>
            </div>
          </div>
        </div>
      </div>
      <!-- </fieldset> -->
    </div>
  </div>
  <script src="../../lib/layui-v2.6.3/layui.js"></script>
  <script src="../../js/basic-load.js" charset="utf-8"></script>
  <script>
    /**
     * 
     * 初始化下拉栏的表单
     * 
     * 
    */
    function setList(){
      /**
       * 
       * 初始化医生下拉栏
       * 
       * */
      layui.$.ajax({
          url: `${url_basic}/doctor/all?onlySelect=id,name`,
          type: "POST",
          contentType: 'application/json',
          success: function (data, textStatus) {

            if (data.code == 0) {
              document.getElementById("surgeon").innerHTML = "";
              for (let index = 0; index < data.data.length; index++) {
                const element = data.data[index];
                var newOption = document.createElement("option");
                newOption.text = element.name;
                newOption.value = element.id;
                document.getElementById("surgeon").add(newOption);
              }
              layui.form.render("select");
              return true;
            }
            else {
              layer.msg('失败，原因：' + data.msg);
              return false;
            }
          },
          error: function (xhr, errorText, errorType) {

            layer.msg('更新清单失败（与服务器连接失败）');
          },

          dataType: "json"
        })

      /**
       * 
       * 初始化起搏器下拉栏
       * 
       * */
      layui.$.ajax({
        url: `${url_basic}/pacemaker/all?onlySelect=id,name`,
        type: "POST",
        contentType: 'application/json',
        success: function (data, textStatus) {

          if (data.code == 0) {
            document.getElementById("pacemakerId").innerHTML = "";
            for (let index = 0; index < data.data.length; index++) {
              const element = data.data[index];
              var newOption = document.createElement("option");
              newOption.text = element.name;
              newOption.value = element.id;
              document.getElementById("pacemakerId").add(newOption);
            }
            layui.form.render("select");
            return true;
          }
          else {
            layer.msg('失败，原因：' + data.msg);
            return false;
          }
        },
        error: function (xhr, errorText, errorType) {

          layer.msg('更新清单失败（与服务器连接失败）');
        },

        dataType: "json"
      })
      /**
       * 
       * 初始化导线下拉栏
       * 
       * */
      var wireIds = ['wireId_1','wireId_2','wireId_3']
      layui.$.ajax({
          url: `${url_basic}/wire/all?onlySelect=id,modelNumber`,
          type: "POST",
          contentType: 'application/json',
          success: function (data, textStatus) {

            if (data.code == 0) {
              for (key in wireIds) {
                obj = document.getElementById(wireIds[key])
                obj.innerHTML = "";
                for (let index = 0; index < data.data.length; index++) {
                  const element = data.data[index];
                  var newOption = document.createElement("option");
                  newOption.text = element.modelNumber;
                  newOption.value = element.id;
                  obj.add(newOption);
                }
              }
              layui.form.render("select");
              return true;
            }
            else {
              layer.msg('失败，原因：' + data.msg);
              return false;
            }
          },
          error: function (xhr, errorText, errorType) {

            layer.msg('更新清单失败（与服务器连接失败）');
          },

          dataType: "json"
        })
    }

    var method = "新增" // 也可能是"修改"，由传参决定
    /**
     * 
     * 植入起搏器原因切换
     * 
     * */
    function cleanSingleChoice(){
      var itmhide = ['reason_more_1','reason_more_2','reason_more_3']
      for(var key in itmhide){
        if(!document.getElementById(itmhide[key]).classList.contains('layui-hide')){
          document.getElementById(itmhide[key]).classList.add('layui-hide');
        }
      }
    }

    /**
     * 
     * layui核心设置
     * 
     * */
    layui.use(['laydate', 'form', 'jquery', 'table'], function () {
      var laydate = layui.laydate,
        form = layui.form,
        table = layui.table,
        $ = layui.$;
      /**
       * 
       * 设置layui时间选择器
       * 
       * */
      var datatime_elems = document.getElementsByClassName("date-time")
      for (var i = 0; i < datatime_elems.length; i++) {
          laydate.render({
              elem: datatime_elems[i]
              , type: 'datetime'
          });
      }
      /**
       * 
       * 设置layui选项卡
       * 
       * */
      setList();

      /**
       * 
       * 设置layui输入框值校验
       * 
       * */
      form.verify({
      // 通用限制
        //id不超过20个字符
        id: [
          /^(\d{0,20})?$/
          , '最大长度不超过20位数'
        ]
        //手机号为11位手机号
        ,phoneNum:[
          /^(\d{11})?$/
          , '请正确输入11位手机号'
        ]      
      //普通搜索限制
        //姓名不超过33个字符
        ,realName:function (value) {
          if (value.length > 33) {
            return '最大长度不超过33个字符';
          }
        }          
        //随访阶段不超过10个字符
        ,followPace:function (value) {
          if (value.length > 10) {
            return '最大长度不超过10个字符';
          }
        }
        //高级搜索限制
          //身份证号限制
          ,idNumber:[
            /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$|^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]|^(\d{0})?$/
            , '请正确输入15位或18位身份证号'
          ]
          //植入原因不超过20个字符
          ,reason:function (value) {
            if (value.length > 20) {
              return '最大长度不超过20个字符';
            }
          }
          //详细介绍、手术过程不超过32767个字符
          ,intro_detail:function (value) {
            if (value.length > 32767) {
              return '输入字符超过最大限制！';
            }
          }
          //医院名称
          ,hospital:function (value) {
            if (value.length > 33) {
              return '最大长度不超过33个字符';
              }
            }
        //添加额外的
          //复选框校验
          ,fuxuan:function () {
            var checked=document.getElementById("wirePosition"); 
            if(checked.checked==false){
              return '请至少选择一个植入位置';
            }
          }
        //其他详细信息校验
          //其他里的详细信息校验
          ,elseinfo:function (value) {
            var checked=document.getElementById("reason_3"); 
            if (value.length < 1 && checked.checked==true) {
              return '请输入其他原因的具体信息';
              }
          }
          //多选框校验
          ,fuxuan:function () {
            var checked1=document.getElementById("wireP1"); 
            var checked2=document.getElementById("wireP2"); 
            var checked3=document.getElementById("wireP3"); 
            var checked=checked1.checked||checked2.checked||checked3.checked
            if(checked==false){
              return '请至少选择一个植入位置';
            }
          }
          //右心房校验
          ,checkrf:function(value){
            var checked=document.getElementById("wireP1");
            if(checked.cheked==true && value.length<1){
              return '请填写右心房必填信息';
            } 
          }
          //右心室校验
          ,checkrs:function(value){
            var checked=document.getElementById("wireP2");
            if(checked.cheked==true && value.length<1){
              return '请填写右心室必填信息';
            } 
          }
          //左心室校验
          ,checkls:function(value){
            var checked=document.getElementById("wireP3");
            if(checked.cheked==true && value.length<1){
              return '请填写左心室必填信息';
            } 
          }
        //导线记录相关
          //浮点数检验
          ,wireRe_f:[
          /^[0-9][0-9]*([\.][0-9]{1,2})?$|^(\d{0})?$/
          , '请输入正确的小数格式'
          ]          
          //日期
          ,datetime2:function(){
            var date1=document.getElementById("createTime").value;
            var date2=document.getElementById("nextTime").value;
            if(date1>date2){
              return '下次随访时间应该晚于植入时间'
            }
          }
      });

      /**
       * 
       * 植入起搏器的位置的切换
       * 
       * */
      form.on('checkbox(wirePosition)', function(data){

        if(data.elem.checked){
          document.getElementById('wirePosition_' + data.value).classList.remove('layui-hide');
        }else{
          document.getElementById('wirePosition_' + data.value).classList.add('layui-hide');
        }
      });

      /**
       * 
       * 植入起搏器的原因的切换
       * 
       * */
      form.on('radio(reason)', function(data){

        cleanSingleChoice()
        if(data.value.substring(0,2) == '房室'){
          document.getElementById('reason_more_1').classList.remove('layui-hide');
        }else if(data.value.substring(0,2) == '心衰'){
          document.getElementById('reason_more_2').classList.remove('layui-hide');
        }else if(data.value.substring(0,2) == '其他'){
          document.getElementById('reason_more_3').classList.remove('layui-hide');
        }
      });  
      /**
       * 
       * 拼接复杂原因
       * 
       * */
      form.on('select(reason_more_1)', function(data){

        document.getElementById('reason_1').value = "房室传导阻滞" + data.value;
      });    
      form.on('select(reason_more_2)', function(data){

        document.getElementById('reason_2').value = "心衰" + data.value;
      });       

      //监听提交
      var content_1 = ['position_1','wireId_1','tdpw_1','prwave_1','pacingImpedance_1','defibrillationEnergy_1','defibrillationImpedance_1']
      var content_2 = ['position_2','wireId_2','tdpw_2','prwave_2','pacingImpedance_2','defibrillationEnergy_2','defibrillationImpedance_2']
      var content_3 = ['position_3','wireId_3','tdpw_3','prwave_3','pacingImpedance_3','defibrillationEnergy_3','defibrillationImpedance_3']
      form.on('submit(saveBtn)', function (data) {
        if(data.field['hospital']===''){
          data.field['hospital'] = "中南医院"
        }
        /**
         * 
         * 删除为空项
         * 
         * */
        for (var key in data.field) {
          if (data.field[key] === '')
            delete data.field[key]
        }
        /**
         * 
         * 对新增删除id以自动分配
         * 
         * */

        if(method == '新增'){
          delete data.field["id"]
        }
        /**
         * 
         * 为电极位置的发送准备数据
         * 
         * */
        var data_in = {"1":{},"2":{},"3":{}};
        var data_tag = [0,0,0,0]
        for(var key in data.field){
          if(content_1.includes(key)){
            data_in["1"][key.slice(0,-2)] = data.field[key];
            data_tag[1]++;
            delete data.field[key]
          }
          else if(content_2.includes(key)){
            data_in["2"][key.slice(0,-2)] = data.field[key];
            data_tag[2]++
            delete data.field[key]
          }
          else if(content_3.includes(key)){
            data_in["3"][key.slice(0,-2)] = data.field[key];
            data_tag[3]++;
            delete data.field[key]
          }
        }
        var heart = ['右心房','右心室','左心室']
        for(var i = 1;i < 4 ;i++){
          if(data_tag[i]<6 && $(`#wireP${i}`).prop("checked")){
            layer.msg('请输入完整的'+ heart[i-1] +'信息');
            return false;
          }
        }
        if(data_tag[1] == 6){
          data.field["raIn"] = true
        }else{
          data.field["raIn"] = false
        }
        if(data_tag[2] == 6){
          data.field["rvIn"] = true
        }else{
          data.field["rvIn"] = false
        }
        if(data_tag[3] == 6){
          data.field["lvIn"] = true
        }else{
          data.field["lvIn"] = false
        }

        /**
         * 
         * 部分自动演算的量,先写死
         * 
         * */
        var storeID=sessionStorage.getItem("store_docid")
        if(storeID!=null){
          data.field["doctorId"] = storeID
        }
        else{
          window.location.assign("../login.html");
        }
        
        data.field["followPace"] = "初期"
        data.field["state"] = 1

        /**
         * 
         * 校验发送数据
         * 
         * */
        // //console.log('新增用户信息，发送数据如下：')
        // //console.log(JSON.stringify(data.field))

        /**
         * 
         * 发送区
         * 
         * */
        $.ajax({
          url: `${url_basic}/medicalRecords/add`,
          type: "POST",
          data: JSON.stringify(data.field),
          contentType: 'application/json',
          success: function (data, textStatus) {
            if (data.code == 0) {
              /**
               * 
               * 发送电极位置信息
               * 
               * */
              for(var i = 1;i < 4 ;i++){
                if(data_tag[i] == 6){
                  data_in[i]["recordId"] = data.id;
                  data_in[i]["position"] = i;
                  $.ajax({
                    url: `${url_basic}/recordWire/add`,
                    type: "POST",
                    data: JSON.stringify(data_in[i]),
                    contentType: 'application/json',
                    success: function (data, textStatus) {
                      if (data.code == 0) {
                        layer.msg('成功', { time: 0.5 * 1000 }, function () {
                          // 关闭弹出层
                          var iframeIndex = parent.layer.getFrameIndex(window.name);
                          parent.layer.close(iframeIndex);
                        });
                        return true;
                      }
                      else {
                        layer.msg(heart[i - 1] + '添加失败，原因：' + data.msg);
                        return false;
                      }
                    },
                    error: function (xhr, errorText, errorType) {
                      layer.msg('添加电极信息失败（与服务器连接失败）');
                    },
                    dataType: "json"
                  })
                }
              }
              return true;
            }
            else {
              layer.msg('失败，原因：' + data.msg);
              return false;
            }
          },
          error: function (xhr, errorText, errorType) {
            layer.msg('修改失败（与服务器连接失败）');
          },
          dataType: "json"
        })
        return false;
      });
    });



    function setData(data, privilege) {
      this_privilege = privilege
      document.getElementById('id').value = '注册后分配'
    };
    function resetPassword(){
      document.getElementById('passwordBlock').style.visibility = "visible"
    };
    document.getElementById("reason_more_3").onchange = function (event) {
      document.getElementById('reason_3').value = "其他：" + event.target.value;
    };
  </script>
</body>

</html>